/* Copyright 2017, 2018, 2019, 2020 Gabriel Czernikier
 *
 * This file is part of Côtehaus.
 * Côtehaus is free software: you can redistribute it and/or modify
 * it under the terms of one of the following:
 * 1. The same dual license as that of Côtehaus itself, of which individual licenses are
 * the MIT License and the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 2. The MIT License.
 * 3. The GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * Côtehaus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * MIT License and the GNU General Public License for more details.
 * You should have received a copy of the MIT License and the GNU General Public License
 * along with Côtehaus.  If not, see <https://opensource.org/licenses/MIT> and <http://www.gnu.org/licenses/>.
 */

/* examples:
 * ident_right("a" "b" "c" "d", "a" "b") == "c" "d"
 * ident_right("a" "b" "c", "b" "c") == "a" "b" "c"
 * ident_right("a" "b", "a" "b" "c") == "a" "b"
 * ident_right("a", "a") == NULL
 */
struct ident_st *ident_right(struct ident_st *what, struct ident_st left) {
	struct ident_st
		*what_course = what,
		*left_course = &left;
	int compar=lgwseq_t_compar(&what->ident, &left.ident);

	while(!compar)  {
		what_course=list_peek_next_entry(what_course, struct ident_st, ident_list, &what.head);
		left_course=list_peek_next_entry(left_course, struct ident_st, ident_list, &left.head);
		if(!what_course || !left_course)
			break;
		compar=lgwseq_t_compar(&what.ident, &left.ident);
	}
	if(left_course==NULL) {
		return what_course;
	}
	return what;
}

